using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace Data_Access_Tier
{
	public class HRM_CONTRACTData : DatabaseObjectBase
	{
		public HRM_CONTRACTData()
		{
			Initialize(true);
		}
		public HRM_CONTRACTData(Boolean newConnection)
		{
			Initialize(newConnection);
		}

		public Int32 HRM_CONTRACT_Insert(String ContractCode, String EmployeeCode, Int32 ContractType, String ContractTime, DateTime SignDate, DateTime FromDate, DateTime ToDate, Decimal BasicSalary, String PayForm, String PayDate, String Allowance, String Insurance, String WorkTime, Decimal Compensation, String Signer, String SignerPosition, String SignerNationality, String Company, String Address, String Tel, String CreatePlace, String Subject, String Description, Boolean IsCurrent)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.InsertCommand = new SqlCommand("HRM_CONTRACT_Insert");
				_dbadapter.InsertCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.InsertCommand.Connection = _dbconn;
				_trans = _dbconn.BeginTransaction();
				_dbadapter.InsertCommand.Transaction = _trans;
				_dbadapter.InsertCommand.Parameters.Clear();
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@ContractCode", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@ContractType", SqlDbType.Int));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@ContractTime", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@SignDate", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@FromDate", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@ToDate", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@BasicSalary", SqlDbType.Money));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@PayForm", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@PayDate", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Allowance", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Insurance", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@WorkTime", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Compensation", SqlDbType.Money));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Signer", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@SignerPosition", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@SignerNationality", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Company", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Address", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Tel", SqlDbType.VarChar, 50));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@CreatePlace", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Subject", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@IsCurrent", SqlDbType.Bit));
				_dbadapter.InsertCommand.Prepare();
				SqlString ContractCodeSQL = ContractCode;
				_dbadapter.InsertCommand.Parameters["@ContractCode"].Value = ContractCodeSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.InsertCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlInt32 ContractTypeSQL = ContractType;
				_dbadapter.InsertCommand.Parameters["@ContractType"].Value = ContractTypeSQL;
				SqlString ContractTimeSQL = ContractTime;
				_dbadapter.InsertCommand.Parameters["@ContractTime"].Value = ContractTimeSQL;
				SqlDateTime SignDateSQL = SqlDateTime.Null;
				if (SignDate > DateTime.MinValue)
				{
					try
					{
						SignDateSQL = SignDate;
					}
					catch (Exception eSignDate)
					{
						String SignDateMessage = eSignDate.Message;
						SignDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@SignDate"].Value = SignDateSQL;
				SqlDateTime FromDateSQL = SqlDateTime.Null;
				if (FromDate > DateTime.MinValue)
				{
					try
					{
						FromDateSQL = FromDate;
					}
					catch (Exception eFromDate)
					{
						String FromDateMessage = eFromDate.Message;
						FromDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@FromDate"].Value = FromDateSQL;
				SqlDateTime ToDateSQL = SqlDateTime.Null;
				if (ToDate > DateTime.MinValue)
				{
					try
					{
						ToDateSQL = ToDate;
					}
					catch (Exception eToDate)
					{
						String ToDateMessage = eToDate.Message;
						ToDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@ToDate"].Value = ToDateSQL;
				SqlMoney BasicSalarySQL = BasicSalary;
				_dbadapter.InsertCommand.Parameters["@BasicSalary"].Value = BasicSalarySQL;
				SqlString PayFormSQL = PayForm;
				_dbadapter.InsertCommand.Parameters["@PayForm"].Value = PayFormSQL;
				SqlString PayDateSQL = PayDate;
				_dbadapter.InsertCommand.Parameters["@PayDate"].Value = PayDateSQL;
				SqlString AllowanceSQL = Allowance;
				_dbadapter.InsertCommand.Parameters["@Allowance"].Value = AllowanceSQL;
				SqlString InsuranceSQL = Insurance;
				_dbadapter.InsertCommand.Parameters["@Insurance"].Value = InsuranceSQL;
				SqlString WorkTimeSQL = WorkTime;
				_dbadapter.InsertCommand.Parameters["@WorkTime"].Value = WorkTimeSQL;
				SqlMoney CompensationSQL = Compensation;
				_dbadapter.InsertCommand.Parameters["@Compensation"].Value = CompensationSQL;
				SqlString SignerSQL = Signer;
				_dbadapter.InsertCommand.Parameters["@Signer"].Value = SignerSQL;
				SqlString SignerPositionSQL = SignerPosition;
				_dbadapter.InsertCommand.Parameters["@SignerPosition"].Value = SignerPositionSQL;
				SqlString SignerNationalitySQL = SignerNationality;
				_dbadapter.InsertCommand.Parameters["@SignerNationality"].Value = SignerNationalitySQL;
				SqlString CompanySQL = Company;
				_dbadapter.InsertCommand.Parameters["@Company"].Value = CompanySQL;
				SqlString AddressSQL = Address;
				_dbadapter.InsertCommand.Parameters["@Address"].Value = AddressSQL;
				SqlString TelSQL = Tel;
				_dbadapter.InsertCommand.Parameters["@Tel"].Value = TelSQL;
				SqlString CreatePlaceSQL = CreatePlace;
				_dbadapter.InsertCommand.Parameters["@CreatePlace"].Value = CreatePlaceSQL;
				SqlString SubjectSQL = Subject;
				_dbadapter.InsertCommand.Parameters["@Subject"].Value = SubjectSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.InsertCommand.Parameters["@Description"].Value = DescriptionSQL;
				SqlBoolean IsCurrentSQL = IsCurrent;
				_dbadapter.InsertCommand.Parameters["@IsCurrent"].Value = IsCurrentSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.InsertCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_CONTRACT_Insert: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_CONTRACT_Insert: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.InsertCommand != null)
					_dbadapter.InsertCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_CONTRACT_Update(String ContractCode, String EmployeeCode, Int32 ContractType, String ContractTime, DateTime SignDate, DateTime FromDate, DateTime ToDate, Decimal BasicSalary, String PayForm, String PayDate, String Allowance, String Insurance, String WorkTime, Decimal Compensation, String Signer, String SignerPosition, String SignerNationality, String Company, String Address, String Tel, String CreatePlace, String Subject, String Description, Boolean IsCurrent)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_CONTRACT_Update");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ContractCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ContractType", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ContractTime", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SignDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@FromDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ToDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@BasicSalary", SqlDbType.Money));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@PayForm", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@PayDate", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Allowance", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Insurance", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@WorkTime", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Compensation", SqlDbType.Money));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Signer", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SignerPosition", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SignerNationality", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Company", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Address", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Tel", SqlDbType.VarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@CreatePlace", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Subject", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsCurrent", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlString ContractCodeSQL = ContractCode;
				_dbadapter.UpdateCommand.Parameters["@ContractCode"].Value = ContractCodeSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.UpdateCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlInt32 ContractTypeSQL = ContractType;
				_dbadapter.UpdateCommand.Parameters["@ContractType"].Value = ContractTypeSQL;
				SqlString ContractTimeSQL = ContractTime;
				_dbadapter.UpdateCommand.Parameters["@ContractTime"].Value = ContractTimeSQL;
				SqlDateTime SignDateSQL = SqlDateTime.Null;
				if (SignDate > DateTime.MinValue)
				{
					try
					{
						SignDateSQL = SignDate;
					}
					catch (Exception eSignDate)
					{
						String SignDateMessage = eSignDate.Message;
						SignDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@SignDate"].Value = SignDateSQL;
				SqlDateTime FromDateSQL = SqlDateTime.Null;
				if (FromDate > DateTime.MinValue)
				{
					try
					{
						FromDateSQL = FromDate;
					}
					catch (Exception eFromDate)
					{
						String FromDateMessage = eFromDate.Message;
						FromDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@FromDate"].Value = FromDateSQL;
				SqlDateTime ToDateSQL = SqlDateTime.Null;
				if (ToDate > DateTime.MinValue)
				{
					try
					{
						ToDateSQL = ToDate;
					}
					catch (Exception eToDate)
					{
						String ToDateMessage = eToDate.Message;
						ToDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@ToDate"].Value = ToDateSQL;
				SqlMoney BasicSalarySQL = BasicSalary;
				_dbadapter.UpdateCommand.Parameters["@BasicSalary"].Value = BasicSalarySQL;
				SqlString PayFormSQL = PayForm;
				_dbadapter.UpdateCommand.Parameters["@PayForm"].Value = PayFormSQL;
				SqlString PayDateSQL = PayDate;
				_dbadapter.UpdateCommand.Parameters["@PayDate"].Value = PayDateSQL;
				SqlString AllowanceSQL = Allowance;
				_dbadapter.UpdateCommand.Parameters["@Allowance"].Value = AllowanceSQL;
				SqlString InsuranceSQL = Insurance;
				_dbadapter.UpdateCommand.Parameters["@Insurance"].Value = InsuranceSQL;
				SqlString WorkTimeSQL = WorkTime;
				_dbadapter.UpdateCommand.Parameters["@WorkTime"].Value = WorkTimeSQL;
				SqlMoney CompensationSQL = Compensation;
				_dbadapter.UpdateCommand.Parameters["@Compensation"].Value = CompensationSQL;
				SqlString SignerSQL = Signer;
				_dbadapter.UpdateCommand.Parameters["@Signer"].Value = SignerSQL;
				SqlString SignerPositionSQL = SignerPosition;
				_dbadapter.UpdateCommand.Parameters["@SignerPosition"].Value = SignerPositionSQL;
				SqlString SignerNationalitySQL = SignerNationality;
				_dbadapter.UpdateCommand.Parameters["@SignerNationality"].Value = SignerNationalitySQL;
				SqlString CompanySQL = Company;
				_dbadapter.UpdateCommand.Parameters["@Company"].Value = CompanySQL;
				SqlString AddressSQL = Address;
				_dbadapter.UpdateCommand.Parameters["@Address"].Value = AddressSQL;
				SqlString TelSQL = Tel;
				_dbadapter.UpdateCommand.Parameters["@Tel"].Value = TelSQL;
				SqlString CreatePlaceSQL = CreatePlace;
				_dbadapter.UpdateCommand.Parameters["@CreatePlace"].Value = CreatePlaceSQL;
				SqlString SubjectSQL = Subject;
				_dbadapter.UpdateCommand.Parameters["@Subject"].Value = SubjectSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				SqlBoolean IsCurrentSQL = IsCurrent;
				_dbadapter.UpdateCommand.Parameters["@IsCurrent"].Value = IsCurrentSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_CONTRACT_Update: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_CONTRACT_Update: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_CONTRACT_Disable(String ContractCode, ref Boolean Enabled)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_CONTRACT_Disable");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ContractCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@enabled", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlString ContractCodeSQL = ContractCode;
				_dbadapter.UpdateCommand.Parameters["@ContractCode"].Value = ContractCodeSQL;
				_dbadapter.UpdateCommand.Parameters["@enabled"].Direction = ParameterDirection.Output;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_CONTRACT_Disable: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_CONTRACT_Disable: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_CONTRACT_Delete(String ContractCode)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.DeleteCommand = new SqlCommand("HRM_CONTRACT_Delete");
				_dbadapter.DeleteCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.DeleteCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.DeleteCommand.Transaction = _trans;

				_dbadapter.DeleteCommand.Parameters.Clear();
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@ContractCode", SqlDbType.VarChar, 20));
				_dbadapter.DeleteCommand.Prepare();
				SqlString ContractCodeSQL = ContractCode;
				_dbadapter.DeleteCommand.Parameters["@ContractCode"].Value = ContractCodeSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.DeleteCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_CONTRACT_Delete: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_CONTRACT_Delete: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.DeleteCommand != null)
					_dbadapter.DeleteCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_CONTRACT_Save(String ContractCode, String EmployeeCode, Int32 ContractType, String ContractTime, DateTime SignDate, DateTime FromDate, DateTime ToDate, Decimal BasicSalary, String PayForm, String PayDate, String Allowance, String Insurance, String WorkTime, Decimal Compensation, String Signer, String SignerPosition, String SignerNationality, String Company, String Address, String Tel, String CreatePlace, String Subject, String Description, Boolean IsCurrent)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_CONTRACT_Save");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ContractCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ContractType", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ContractTime", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SignDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@FromDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ToDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@BasicSalary", SqlDbType.Money));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@PayForm", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@PayDate", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Allowance", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Insurance", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@WorkTime", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Compensation", SqlDbType.Money));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Signer", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SignerPosition", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@SignerNationality", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Company", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Address", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Tel", SqlDbType.VarChar, 50));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@CreatePlace", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Subject", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsCurrent", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlString ContractCodeSQL = ContractCode;
				_dbadapter.UpdateCommand.Parameters["@ContractCode"].Value = ContractCodeSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.UpdateCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlInt32 ContractTypeSQL = ContractType;
				_dbadapter.UpdateCommand.Parameters["@ContractType"].Value = ContractTypeSQL;
				SqlString ContractTimeSQL = ContractTime;
				_dbadapter.UpdateCommand.Parameters["@ContractTime"].Value = ContractTimeSQL;
				SqlDateTime SignDateSQL = SqlDateTime.Null;
				if (SignDate > DateTime.MinValue)
				{
					try
					{
						SignDateSQL = SignDate;
					}
					catch (Exception eSignDate)
					{
						String SignDateMessage = eSignDate.Message;
						SignDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@SignDate"].Value = SignDateSQL;
				SqlDateTime FromDateSQL = SqlDateTime.Null;
				if (FromDate > DateTime.MinValue)
				{
					try
					{
						FromDateSQL = FromDate;
					}
					catch (Exception eFromDate)
					{
						String FromDateMessage = eFromDate.Message;
						FromDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@FromDate"].Value = FromDateSQL;
				SqlDateTime ToDateSQL = SqlDateTime.Null;
				if (ToDate > DateTime.MinValue)
				{
					try
					{
						ToDateSQL = ToDate;
					}
					catch (Exception eToDate)
					{
						String ToDateMessage = eToDate.Message;
						ToDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@ToDate"].Value = ToDateSQL;
				SqlMoney BasicSalarySQL = BasicSalary;
				_dbadapter.UpdateCommand.Parameters["@BasicSalary"].Value = BasicSalarySQL;
				SqlString PayFormSQL = PayForm;
				_dbadapter.UpdateCommand.Parameters["@PayForm"].Value = PayFormSQL;
				SqlString PayDateSQL = PayDate;
				_dbadapter.UpdateCommand.Parameters["@PayDate"].Value = PayDateSQL;
				SqlString AllowanceSQL = Allowance;
				_dbadapter.UpdateCommand.Parameters["@Allowance"].Value = AllowanceSQL;
				SqlString InsuranceSQL = Insurance;
				_dbadapter.UpdateCommand.Parameters["@Insurance"].Value = InsuranceSQL;
				SqlString WorkTimeSQL = WorkTime;
				_dbadapter.UpdateCommand.Parameters["@WorkTime"].Value = WorkTimeSQL;
				SqlMoney CompensationSQL = Compensation;
				_dbadapter.UpdateCommand.Parameters["@Compensation"].Value = CompensationSQL;
				SqlString SignerSQL = Signer;
				_dbadapter.UpdateCommand.Parameters["@Signer"].Value = SignerSQL;
				SqlString SignerPositionSQL = SignerPosition;
				_dbadapter.UpdateCommand.Parameters["@SignerPosition"].Value = SignerPositionSQL;
				SqlString SignerNationalitySQL = SignerNationality;
				_dbadapter.UpdateCommand.Parameters["@SignerNationality"].Value = SignerNationalitySQL;
				SqlString CompanySQL = Company;
				_dbadapter.UpdateCommand.Parameters["@Company"].Value = CompanySQL;
				SqlString AddressSQL = Address;
				_dbadapter.UpdateCommand.Parameters["@Address"].Value = AddressSQL;
				SqlString TelSQL = Tel;
				_dbadapter.UpdateCommand.Parameters["@Tel"].Value = TelSQL;
				SqlString CreatePlaceSQL = CreatePlace;
				_dbadapter.UpdateCommand.Parameters["@CreatePlace"].Value = CreatePlaceSQL;
				SqlString SubjectSQL = Subject;
				_dbadapter.UpdateCommand.Parameters["@Subject"].Value = SubjectSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				SqlBoolean IsCurrentSQL = IsCurrent;
				_dbadapter.UpdateCommand.Parameters["@IsCurrent"].Value = IsCurrentSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_CONTRACT_Save: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_CONTRACT_Save: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_CONTRACT_GetList()
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_CONTRACT_GetList");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Prepare();
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_CONTRACT_GetList: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_CONTRACT_Get(String ContractCode)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_CONTRACT_Get");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@ContractCode", SqlDbType.VarChar, 20));
				_dbadapter.SelectCommand.Prepare();
				SqlString ContractCodeSQL = ContractCode;
				_dbadapter.SelectCommand.Parameters["@ContractCode"].Value = ContractCodeSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_CONTRACT_Get: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}

        public DataSet HRM_CONTRACT_GetByContract(String ContractCode, String EmployeeCode)
        {
            try
            {
                if (_dbconn.State != ConnectionState.Open)
                    _dbconn.Open();
                _dbadapter.SelectCommand = new SqlCommand("HRM_CONTRACT_GetByContract");
                _dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _dbadapter.SelectCommand.Connection = _dbconn;
                _dbadapter.SelectCommand.Parameters.Clear();
                _dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@ContractCode", SqlDbType.VarChar, 20));
                _dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
                _dbadapter.SelectCommand.Prepare();
                SqlString ContractCodeSQL = ContractCode;
                SqlString EmployeeCodeSQL = EmployeeCode;
                _dbadapter.SelectCommand.Parameters["@ContractCode"].Value = ContractCodeSQL;
                _dbadapter.SelectCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
                _dbadapter.Fill(_data);

                return _data;
            }
            catch (SqlException e)
            {
                throw new Exception("SQL Error: HRM_CONTRACT_GetByContract: " + e.Message, e);
            }
            finally
            {
                if (_dbadapter.SelectCommand != null)
                    _dbadapter.SelectCommand.Dispose();
                CloseConnection();
            }
        }

        public DataSet HRM_CONTRACT_GetByEmployee(String EmployeeCode)
        {
            try
            {
                if (_dbconn.State != ConnectionState.Open)
                    _dbconn.Open();
                _dbadapter.SelectCommand = new SqlCommand("HRM_CONTRACT_GetByEmployee");
                _dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _dbadapter.SelectCommand.Connection = _dbconn;
                _dbadapter.SelectCommand.Parameters.Clear();
                _dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
                _dbadapter.SelectCommand.Prepare();
                SqlString EmployeeCodeSQL = EmployeeCode;
                _dbadapter.SelectCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
                _dbadapter.Fill(_data);

                return _data;
            }
            catch (SqlException e)
            {
                throw new Exception("SQL Error: HRM_CONTRACT_GetByEmployee: " + e.Message, e);
            }
            finally
            {
                if (_dbadapter.SelectCommand != null)
                    _dbadapter.SelectCommand.Dispose();
                CloseConnection();
            }
        }

        public DataSet HRM_CONTRACT_GetCurrentList()
        {
            try
            {
                if (_dbconn.State != ConnectionState.Open)
                    _dbconn.Open();
                _dbadapter.SelectCommand = new SqlCommand("HRM_CONTRACT_GetCurrentList");
                _dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _dbadapter.SelectCommand.Connection = _dbconn;
                _dbadapter.SelectCommand.Parameters.Clear();
               
                _dbadapter.SelectCommand.Prepare();
                
                _dbadapter.Fill(_data);

                return _data;
            }
            catch (SqlException e)
            {
                throw new Exception("SQL Error: HRM_CONTRACT_GetCurrentList: " + e.Message, e);
            }
            finally
            {
                if (_dbadapter.SelectCommand != null)
                    _dbadapter.SelectCommand.Dispose();
                CloseConnection();
            }
        }

        public DataSet HRM_CONTRACT_GetListByBranch(String BranchCode)
        {
            try
            {
                if (_dbconn.State != ConnectionState.Open)
                    _dbconn.Open();
                _dbadapter.SelectCommand = new SqlCommand("HRM_CONTRACT_GetListByBranch");
                _dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _dbadapter.SelectCommand.Connection = _dbconn;
                _dbadapter.SelectCommand.Parameters.Clear();
                _dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@BranchCode", SqlDbType.VarChar, 20));
                _dbadapter.SelectCommand.Prepare();
                SqlString BranchCodeSQL = BranchCode;
                _dbadapter.SelectCommand.Parameters["@BranchCode"].Value = BranchCodeSQL;
                _dbadapter.Fill(_data);

                return _data;
            }
            catch (SqlException e)
            {
                throw new Exception("SQL Error: HRM_CONTRACT_GetListByBranch: " + e.Message, e);
            }
            finally
            {
                if (_dbadapter.SelectCommand != null)
                    _dbadapter.SelectCommand.Dispose();
                CloseConnection();
            }
        }

        public DataSet HRM_CONTRACT_GetListByDepartment(String DepartmentCode)
        {
            try
            {
                if (_dbconn.State != ConnectionState.Open)
                    _dbconn.Open();
                _dbadapter.SelectCommand = new SqlCommand("HRM_CONTRACT_GetListByDepartment");
                _dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _dbadapter.SelectCommand.Connection = _dbconn;
                _dbadapter.SelectCommand.Parameters.Clear();
                _dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@DepartmentCode", SqlDbType.VarChar, 20));
                _dbadapter.SelectCommand.Prepare();
                SqlString DepartmentCodeSQL = DepartmentCode;
                _dbadapter.SelectCommand.Parameters["@DepartmentCode"].Value = DepartmentCodeSQL;
                _dbadapter.Fill(_data);

                return _data;
            }
            catch (SqlException e)
            {
                throw new Exception("SQL Error: HRM_CONTRACT_GetListByDepartment: " + e.Message, e);
            }
            finally
            {
                if (_dbadapter.SelectCommand != null)
                    _dbadapter.SelectCommand.Dispose();
                CloseConnection();
            }
        }

        public DataSet HRM_CONTRACT_GetListByGroup(String GroupCode)
        {
            try
            {
                if (_dbconn.State != ConnectionState.Open)
                    _dbconn.Open();
                _dbadapter.SelectCommand = new SqlCommand("HRM_CONTRACT_GetListByGroup");
                _dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _dbadapter.SelectCommand.Connection = _dbconn;
                _dbadapter.SelectCommand.Parameters.Clear();
                _dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@GroupCode", SqlDbType.VarChar, 20));
                _dbadapter.SelectCommand.Prepare();
                SqlString GroupCodeSQL = GroupCode;
                _dbadapter.SelectCommand.Parameters["@GroupCode"].Value = GroupCodeSQL;
                _dbadapter.Fill(_data);

                return _data;
            }
            catch (SqlException e)
            {
                throw new Exception("SQL Error: HRM_CONTRACT_GetListByGroup: " + e.Message, e);
            }
            finally
            {
                if (_dbadapter.SelectCommand != null)
                    _dbadapter.SelectCommand.Dispose();
                CloseConnection();
            }
        }

        public DataSet HRM_CONTRACT_GetListExpiration()
        {
            try
            {
                if (_dbconn.State != ConnectionState.Open)
                    _dbconn.Open();
                _dbadapter.SelectCommand = new SqlCommand("HRM_CONTRACT_GetListExpiration");
                _dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _dbadapter.SelectCommand.Connection = _dbconn;
                _dbadapter.SelectCommand.Parameters.Clear();

                _dbadapter.SelectCommand.Prepare();

                _dbadapter.Fill(_data);

                return _data;
            }
            catch (SqlException e)
            {
                throw new Exception("SQL Error: HRM_CONTRACT_GetListExpiration: " + e.Message, e);
            }
            finally
            {
                if (_dbadapter.SelectCommand != null)
                    _dbadapter.SelectCommand.Dispose();
                CloseConnection();
            }
        }

        public DataSet HRM_CONTRACT_GetListJustExpiration()
        {
            try
            {
                if (_dbconn.State != ConnectionState.Open)
                    _dbconn.Open();
                _dbadapter.SelectCommand = new SqlCommand("HRM_CONTRACT_GetListJustExpiration");
                _dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _dbadapter.SelectCommand.Connection = _dbconn;
                _dbadapter.SelectCommand.Parameters.Clear();

                _dbadapter.SelectCommand.Prepare();

                _dbadapter.Fill(_data);

                return _data;
            }
            catch (SqlException e)
            {
                throw new Exception("SQL Error: HRM_CONTRACT_GetListJustExpiration: " + e.Message, e);
            }
            finally
            {
                if (_dbadapter.SelectCommand != null)
                    _dbadapter.SelectCommand.Dispose();
                CloseConnection();
            }
        }

	}
}
